#include "orderthread.h"

#include <QThread>
#include <QDebug>
#include <QTableWidgetItem>
#include <QTableWidgetItem>
#include <QTableWidgetItem>

#include "../plugin/db.h"

OrderThread::OrderThread(QObject *parent) : QThread(parent), m_param(0)
{
}

void OrderThread::setParam(int param)
{
    m_param = param;
}


void OrderThread::run()
{
    // 线程执行的逻辑（耗时操作放在这里）
    qDebug() << "线程开始执行，参数：" << m_param;
    qDebug() << "线程ID：" << QThread::currentThreadId();

    // 检查线程是否被要求终止
    if (isInterruptionRequested()) {
        qDebug() << "线程被终止";
        return;
    }

    // 发送进度信号给主线程
    emit progress(0);


    Db *db = new Db();
    QVector<QMap<QString, QVariant>> orderList = db->query("select tradeID,createdAt,style,quantity,symbol,price,stopLossPrice,stopProfitPrice,weight,cost,marketPrice,profit from pre_position_purchase where inventorID = '680939' and status = 5 limit 20");

    // 发送结果信号
    emit resultReady(orderList);
    qDebug() << "数据发送成功";
    // 发送进度信号给主线程
    emit progress(1);
}
